package com.walker.taogong.web;

import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.walker.taogong.bll.TaskBll;
import com.walker.taogong.datamodel.Task;

public class TaskDetail
{

    /** Logger. */
    private static Logger log = LoggerFactory.getLogger(TaskDetail.class);

    /************************ BLL 服务引用 *******************************************/

    private TaskBll taskBll;

    public void setTaskBll(TaskBll taskBll)
    {
        this.taskBll = taskBll;
    }

    /************************* 启动测试用 ************************************/
    /**
     * 组件启动初期化
     */
    protected void activate(ComponentContext cc)
    {
        log.info("{} is starting!", cc.getProperties().get("name"));

        try
        {
            // 主流程

            // 1. 点击link连接
            int id = 10;
            
            Task task = taskBll.getTaskInfo(id);

            if (task == null)
            {
                log.info("不能找到对应的任务内容");
                log.info("跳转到Error页面");
            }
            else
            {
                showTaskDetail(task);

            }
        }
        catch (Throwable exc)
        {
            log.error("Terminated with runtime exception", exc);
        }

    }

    private void showTaskDetail(Task task)
    {
        log.info("---------------任务的细节显示-----------------");
        log.info(task.getTaskTitle());
        log.info("it is posted by "  + task.getOwner() + "on " + task.getPostDate());
        log.info(task.getDescription());
        log.info("it will expire on " + task.getConfirmDeadLine());
        log.info("it need be completed on " +  task.getFinishDeadLine());
        log.info("the task status is " + task.getStatus());
        log.info("---------------任务的细节显示-----------------");

    }

}
